//
//  UIButton+Chain.m
//  YJB
//
//  Created by admin on 2017/5/3.
//  Copyright © 2017年 肖世恒. All rights reserved.
//

#import "UIButton+Chain.h"

@implementation UIButton (Chain)
    
+(UIButton *(^)(void))initialization {
    return ^id(void) {
        return [UIButton buttonWithType:UIButtonTypeCustom];
    };
}
    
-(UIButton *(^)(CGRect))rect {
    return ^id(CGRect rect) {
        return [self addRect:rect];
    };
}
    
-(UIButton *(^)(UIColor *))bgColor {
    return ^id(UIColor * color) {
        return [self addBgColor:color];
    };
}
    
-(UIButton *(^)(NSString *))normalTitle {
    return ^id(NSString * title) {
        return [self addNormalTitle:title];
    };
}
    
-(UIButton *(^)(NSString *))selectTitle {
    return ^id(NSString * title) {
        return [self addSelectTitle:title];
    };
}
    
-(UIButton *(^)(id, SEL))action {
    return ^id(id object, SEL method) {
        return [self addTarget:object action:method];
    };
}
    
    /*-------------------------分割线----------------------------*/
-(UIButton *)addRect:(CGRect)rect {
    self.frame = rect;
    return self;
}
    
-(UIButton *)addBgColor:(UIColor *)bgColor {
    self.backgroundColor = bgColor;
    return self;
}
    
-(UIButton *)addNormalTitle:(NSString *)title {
    [self setTitle:title forState:UIControlStateNormal];
    return self;
}
    
-(UIButton *)addSelectTitle:(NSString *)title {
    [self setTitle:title forState:UIControlStateSelected];
    return self;
}
    
-(UIButton *)addTarget:(id)object action:(SEL)action {
    [self addTarget:object action:action forControlEvents:UIControlEventTouchUpInside];
    return self;
}

@end
